<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Room extends Model
{
    public function getReservedAttribute(){
        return $this->is_reserved ? '占用' : '空闲';
    }

    public function setReservedAttribute($value){
        $this->is_reserved = $value === '占用';
    }

    public function room_type(){
        return $this->belongsTo(RoomType::class);
    }

    public function booking(){
        return $this->hasOne(Booking::class);
    }

    public function comments(){
        return $this->hasManyThrough(Comment::class, Booking::class);
    }

    public function scopeUnreserved($query){
        return $query->where('is_reserved', false);
    }
}
